package com.yuantong.xyerp.core.provider.dao;

import com.yuantong.xyerp.core.api.dto.WarehouseRecordsDto;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created by Jianguo.Yin on 2021-08-15.
 */
public interface WarehouseRecordsMapper {

    @Select({"<script> " +
            "SELECT w.*,o.name AS warehouse_name,g.type FROM t_warehouse_records w " +
            "LEFT JOIN t_goods g ON (g.id = w.goods_id) " +
            "LEFT JOIN t_organization o ON (o.id = w.warehouse_id) " +
            "WHERE 1=1 " +
            "<if test=\"fuzzy != null and fuzzy != ''\"> " +
            "<bind name=\"bindKey\" value=\"'%'+fuzzy+'%'\"/> " +
            "AND (w.goods_name LIKE #{bindKey} OR w.category_name LIKE #{bindKey} OR warehouse_name LIKE #{bindKey}) " +
            "</if> " +
            "<if test=\"ids != null and ids.size() > 0\"> " +
            "AND w.id IN " +
            "<foreach collection=\"ids\" item=\"id\" open=\"(\" close=\")\" separator=\",\"> " +
            "#{id} " +
            "</foreach> " +
            "</if> " +
            "ORDER BY w.update_time DESC" +
            "</script>"})
    @ResultMap("WarehouseRecordsDtoResult")
    List<WarehouseRecordsDto> findAllByFuzzy(String fuzzy, List<String> ids);
}
